package com.example.observer.v5.source;

import com.example.observer.v5.event.impl.WakeUpEvent;
import com.example.observer.v5.listener.SourceListener;
import com.example.observer.v5.listener.impl.DadListener;
import com.example.observer.v5.listener.impl.MomListener;
import lombok.ToString;

import java.util.ArrayList;
import java.util.List;

@ToString
public class Child {

    private boolean cry=false;
    private List<SourceListener> listeners=new ArrayList<>();
    {
        listeners.add(new DadListener());
        listeners.add(new MomListener());
    }

    public void wakeUp(){
        System.out.println("wake up wu wu...");
        this.cry=true;
        for (SourceListener listener : listeners) {
            listener.action(new WakeUpEvent(System.currentTimeMillis(),"bed",this));
        }
    }
}
